import 'package:flutter/material.dart';
import 'package:flutter_app/openeye/utils/toast_utils.dart';
import 'package:flutter_app/stateLearn/click_txt.dart';
import 'package:flutter_app/stateLearn/page_one.dart';
import 'package:flutter_app/stateLearn/page_two.dart';

// class StatePage extends StatelessWidget {
//   const StatePage({Key key}) : super(key: key);
//
//   @override
//   Widget build(BuildContext context) {
//     return Scaffold(
//       appBar: AppBar(title: const Text("刷新状态学习"),),
//       body: Center(
//         child: Column(
//           children:  [
//             PageOne(),
//             PageTwo(),
//             ElevatedButton(onPressed: (){
//               debugPrint("刷新主界面");
//             }, child: Text("刷新界面")),
//             TextButton(onPressed: (){
//
//             }, child: Text("增加第一个界面的值")),
//             TextButton(onPressed: (){
//
//             }, child: Text("增加第二个界面的值")),
//           ],
//         ),
//       ),
//     );
//   }
// }

class StatePage extends StatefulWidget {
  const StatePage({Key? key}) : super(key: key);

  @override
  _StatePageState createState() => _StatePageState();
}

class _StatePageState extends State<StatePage> {
  bool showPageOne = true;

  @override
  Widget build(BuildContext context) {
    debugPrint("重构主界面");
    return MaterialApp(
      builder: (context, child) {
        return Scaffold(
          appBar: AppBar(
            title: const Text("刷新状态学习"),
          ),
          body: Center(
            child: Column(
              children: [
                _isShowPageOne(),
                const PageTwo(),
                ClickTxt(
                    info: "这是带点击的文本显示",
                    onPressed: () async {
                      Navigator.of(context)
                          .pushNamed('navigatorLearn')
                          .then((value) {
                        if (value is String) {
                          ToastUtils.showTip(value);
                        }
                      });
                    })
              ],
            ),
          ),
          floatingActionButton: FloatingActionButton(
            onPressed: changeState,
            tooltip: "Update Text",
            child: const Icon(Icons.update),
          ),
        );
      },
    );
  }

  void changeState() {
    setState(() {
      showPageOne = !showPageOne;
    });
  }

  _isShowPageOne() {
    if (showPageOne) {
      return const PageOne();
    } else {
      return const Text("Toggle One");
    }
  }
}
